home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / gsdbloo.exe / DEMOR003.PAS < prev    next >
Pascal/Delphi Source File  |  1992-02-29  |  3KB  |  111 lines

  1. program DemoR003;
  2. {------------------------------------------------------------------------------
  3.                          DBase Relational File Linkage
  4.                               Relational Examples
  5.                                  Demo Program
  6.  
  7.        Copyright (c)  Richard F. Griffin
  8.  
  9.        10 February 1992
  10.  
  11.        102 Molded Stone Pl
  12.        Warner Robins, GA  31088
  13.  
  14.        -------------------------------------------------------------
  15.        This unit demonstrates how to search for multiple records with a
  16.        common identifier.
  17.  
  18.        The master file index is on the UNIQUEID field.  The transaction
  19.        record places this unique identifier in the MASTERID field of the
  20.        transaction record.
  21.  
  22.        The routine will read each master record and list all transactions
  23.        with the master record unique identifier.
  24.  
  25. -------------------------------------------------------------------------------}
  26.  
  27. uses
  28.    CRT,
  29.    GS_Date,
  30.    GS_FileH,
  31.    GS_KeyI,
  32.    GS_Strng,
  33.    GS_dBase,
  34.    GS_dBFld;
  35.  
  36. var
  37.    MstrFile : GS_dBFld_Objt;
  38.    TranFile : GS_dBFld_Objt;
  39.    ftest    : file;
  40.  
  41. begin
  42.    ClrScr;
  43.  
  44.    if not GS_FileExists(ftest, 'DEMOR1MF.DBF') then
  45.    begin
  46.       writeln('File DEMOR1MF.DBF not found.  Run DEMOR001 to create.');
  47.       halt;
  48.    end;
  49.  
  50.    if not GS_FileExists(ftest, 'DEMOR1TF.DBF') then
  51.    begin
  52.       writeln('File DEMOR1TF.DBF not found.  Run DEMOR001 to create.');
  53.       halt;
  54.    end;
  55.  
  56.                        {The 'Real' example starts here}
  57.  
  58.    MstrFile.Init('DEMOR1MF');
  59.    MstrFile.Open;
  60.    MstrFile.Index('DEMOR1ID');
  61.    TranFile.Init('DEMOR1TF');
  62.    TranFile.Open;
  63.    TranFile.Index('DEMOR1TN');
  64.  
  65.    MstrFile.GetRec(Top_Record);
  66.    while not (MstrFile.File_EOF) and (GS_KeyI_Chr <> #27) do
  67.    begin
  68.       ClrScr;
  69.  
  70.                    {Display the master record}
  71.  
  72.       Writeln('':37,'MASTER');
  73.       Writeln;
  74.       Writeln('  LASTNAME : ',MstrFile.FieldGet('LASTNAME'));
  75.       Writeln(' FIRSTNAME : ',MstrFile.FieldGet('FIRSTNAME'));
  76.       Writeln('    STREET : ',MstrFile.FieldGet('STREET'));
  77.       Writeln('   ADDRESS : ',MstrFile.StringGet('CITY'),', ',
  78.                               MstrFile.FieldGet('STATE'),' ',
  79.                               MstrFile.FieldGet('ZIP'));
  80.  
  81.                        {Display transaction information}
  82.  
  83.       Writeln;
  84.       Writeln('':20,'-----------------------------------------');
  85.       Writeln('':34,'TRANSACTION');
  86.       Writeln;
  87.  
  88.                        {Hunt for matching records}
  89.  
  90.       if TranFile.Find(MstrFile.FieldGet('UNIQUEID')) then
  91.       begin
  92.          while (MstrFile.FieldGet('UNIQUEID') = TranFile.FieldGet('MASTERID'))
  93.                 and not TranFile.File_EOF do
  94.          begin
  95.             Writeln(TranFile.FieldGet('FULLNAME'),'  ',
  96.                     GS_Date_View(TranFile.DateGet('TRANDATE')),'  ',
  97.                     TranFile.FieldGet('AMOUNT'));
  98.             TranFile.GetRec(Next_Record);
  99.          end;
  100.       end
  101.       else Writeln('No Transaction Records!');
  102.  
  103.       Writeln;
  104.       Writeln('Press Any Key to Continue: ') ;
  105.       Writeln('[ESC] Will Terminate the Program');
  106.       WaitForKey;
  107.       MstrFile.GetRec(Next_Record);
  108.    end;
  109.    MstrFile.Close;
  110.    TranFile.Close;
  111. end.